﻿#ifndef RECORDER_H
#define RECORDER_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlQueryModel>
#include <QTime>
#include <QWidget>

#include "qcustomplot.h"

namespace Ui {
class Recorder;
}

class Recorder : public QWidget
{
    Q_OBJECT

public:
    explicit Recorder(QWidget *parent = nullptr);
    ~Recorder();
    void setShowIndex(int index); //设置显示分页.
    void initDatabase();          //初始化数据库.

    bool onAdditionEmployee(int userId, QString userName, int finger=-1, int face=-1, QString photo=""); //增加员工.
    bool onRemoveEmployee(int userId); //移除员工.
    void onSearchEmployee(int userId); //查找员工.

signals:
    void sigLoginFinger();  //通知模块注册指纹（异步）.
    void sigLoginFace();    //通知模块注册人脸（异步）.
    void sigSearchModel();  //通知模块返回搜索模式.
    void sigRemoveFinger(int fingerId); //通知模块删除指纹（异步）.
    void sigRemoveFace(int faceId);   //通知模块删除人脸（异步）.
    void sigShowMsg(QString msg); //显示信息.

public slots:
    void onModuleLoginOver(bool flag, int featureId, QString info); //模块注册结束.
    void onUserSign(int featureId); //用户签到or签退.

private:
    void refreshTable(bool user=true, bool attendance=true); //刷新用户表和考勤表.

private:
    Ui::Recorder *ui;
	QString m_dataBaseName;
    QSqlQueryModel m_userInfoModel;
    QSqlQueryModel m_attendanceInfoModel;

    QCPGraph *m_signInGraph {nullptr};
    QCPGraph *m_signOutGraph {nullptr};
};

#endif // RECORDER_H
